package com.cdu.xinmiao.Utils;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.cdu.xinmiao.activity.WeatherActivity;
import com.xuexiang.xui.widget.popupwindow.popup.XUIPopup;

public class PopupUtils extends XUIPopup {
    private Context mContext;

    public PopupUtils(Context context) {
        super(context);
        this.mContext = context;  // 保存Context
        initPopup();
    }

    private void initPopup() {
        // 创建ListView
        ListView listView = new ListView(getContext());
        // 设置ListView的适配器，这里使用简单的ArrayAdapter
        String[] items = {"查看天气", "玩个游戏", "听点音乐"};
        ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_list_item_1, items);
        listView.setAdapter(adapter);

        // 设置ListView的点击事件
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // 处理点击事件
                String item = (String) parent.getItemAtPosition(position);
                // 这里可以进行相应的处理
                switch (position) {
                    case 0:
                        mContext.startActivity(new Intent(mContext, WeatherActivity.class));
                        break;
                    case 1:
//                        mContext.startActivity(new Intent(mContext, Activity2.class));
                        break;
                    case 2:
//                        mContext.startActivity(new Intent(mContext, Activity3.class));
                        break;
                    default:
                        break;
                }
                dismiss(); // 点击后隐藏浮层
            }
        });

        // 设置ListView的宽高
        listView.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT
        ));

        // 设置PopupWindow的内容视图
        setContentView(listView);
    }
}
